package com.frankie.weibo.miweibo.business;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.frankie.weibo.R;
import com.frankie.weibo.miweibo.adapter.StatusItemAdapter;
import com.frankie.weibo.miweibo.base.BaseActivity;
import com.frankie.weibo.miweibo.bean.StatusBean;
import com.frankie.weibo.miweibo.mvp.presenter.MainPresenter;
import com.frankie.weibo.miweibo.mvp.view.IMainView;
import com.github.jdsjlzx.recyclerview.LRecyclerView;
import com.github.jdsjlzx.recyclerview.LRecyclerViewAdapter;
import com.github.jdsjlzx.util.RecyclerViewUtils;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends BaseActivity implements IMainView, View.OnClickListener, LRecyclerView.LScrollListener {

    private int pageNum = 1;
    private MainPresenter presenter;
    private LRecyclerView lRecyclerView;
    private StatusItemAdapter adapter;
    private List<StatusBean> datas;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }

    private void init(){
        presenter = new MainPresenter(this);

        adapter = new StatusItemAdapter(this, datas = new ArrayList<StatusBean>());
        lRecyclerView = (LRecyclerView) findViewById(R.id.list_view);
        lRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        lRecyclerView.setAdapter(new LRecyclerViewAdapter(this, adapter));
        lRecyclerView.setLScrollListener(this);

        lRecyclerView.setRefreshing(true);
        presenter.getStatuses();
    }

    @Override
    public int getPageNum() {
        return pageNum;
    }

    @Override
    public void getStatuses() {

    }

    @Override
    public void refreshList(List<StatusBean> datas) {
        if(getPageNum() == 1)
            this.datas.removeAll(this.datas);
        lRecyclerView.refreshComplete();
        this.datas.addAll(datas);
    }

    @Override
    public void onClick(View v) {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onScrollUp() {}
    @Override
    public void onScrollDown() {}
    @Override
    public void onScrolled(int i, int i1) {}

    @Override
    public void onRefresh() {
        pageNum = 1;
        presenter.getStatuses();
    }
    @Override
    public void onBottom() {
        pageNum++;
        presenter.getStatuses();
    }

}
